<%@ page language="java" contentType="text/html; charset=UTF-8"
  pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%-- 
   Copyright (C) 2010 Google Inc.

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
 --%>
<%@page import="java.util.List"%>
<%@page import="com.google.demo.mrrelease.annotation.AnnotationType"%>
<%@page import="com.google.demo.mrrelease.util.JspUtil"%>
<%!ThreadLocal<HttpServletRequest> currentRequest = new ThreadLocal<HttpServletRequest>();

  String $$(String name) {
    return JspUtil.getAttr(currentRequest.get(), name);
  }%>
<%
  currentRequest.set(request);
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Mr. Release Annotator</title>
</head>
<body>

<h1>Mr. Release Annotator</h1>

<%
  String msg = (String) request.getAttribute("msg");
  if (msg != null && !msg.isEmpty()) {
%>
<p><%=msg%></p>
<%
  }
%>
<form method="post">
<table>
  <thead>
    <tr>
      <th>Regular Expression</th>
      <th>Key</th>
      <th>Value</th>
      <th>Action</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><input type="hidden" name="id" value="<%=$$("id")%>" /><input
        type="text" name="regex" value="<%=$$("regex")%>" /></td>
      <td><input type="text" name="annotationKey"
        value="<%=$$("annotationKey")%>" /></td>
      <td><input type="text" name="annotationValue"
        value="<%=$$("annotationValue")%>" /></td>
      <td>
      <%
      if ($$("id").isEmpty()) {
      %>
      <input name="submit" value="add" type="submit" />
      <%} else { %>
      <input name="submit" value="update" type="submit" />
      <%}%>
      </td>
    </tr>
    <%
      @SuppressWarnings("unchecked")
      List<AnnotationType> list = (List<AnnotationType>) request.getAttribute("annotationTypes");
      for (AnnotationType type : list) {
        // TODO: escape these raw strings
    %>
    <tr>
      <td><%=type.getRegex()%></td>
      <td><%=type.getAnnotationKey()%></td>
      <td><%=type.getAnnotationValue()%></td>
      <td><input name="edit-<%=type.getId()%>" value="edit" type="submit" /><input
        name="delete-<%=type.getId()%>" value="delete" type="submit" /></td>
    </tr>
    <%
      }
    %>

  </tbody>
</table>
</form>

</body>
</html>